package cuiyt.juc.cas;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author cyt
 * @create 2020-05-03 22:35
 */
public class demo01 {
    // cas compareandset : 比较并交换
    public static void main(String[] args) {
        // 得到自己所期望的就会立马更新， 否则就不会更新， 操作系统的原语
        AtomicInteger atomicInteger = new AtomicInteger(2020);
        atomicInteger.compareAndSet(2020,2021);
        System.out.println(atomicInteger.get());
        atomicInteger.getAndIncrement();
        System.out.println(atomicInteger.compareAndSet(2020, 2021));
        System.out.println(atomicInteger.get());
    }
}
